<template>
  <div>
    <div class="bg-btn"><van-button type="info" to="homepage">返回</van-button></div>
    <baidu-map class="map" :center="center" :zoom="zoom" @ready="handler">
      <bm-marker :position="markerPoint" :icon="{url: 'http://i8.mifile.cn/v1/a1/161705c3-99a5-8345-ab6c-84f0422fb501.png', size: {width: 60, height: 60}}"></bm-marker>
    </baidu-map>
    <van-row class="btn">
      <van-col span="5" offset="2">
        <van-button type="default" size="small" @click="num = 0">小米之家</van-button>
      </van-col>
      <van-col span="5">
        <van-button type="default" size="small" @click="num = 1">线下专区</van-button>
      </van-col>
      <van-col span="1" class="text">|</van-col>
      <van-col span="5">
        <van-button type="default" size="small" @click="num = 2">服务网点</van-button>
      </van-col>
      <van-col span="4" offset="1" class="text">
        <van-icon name="search" class="se" />
      </van-col>
    </van-row>
    <div>
      <div class="address-list">
        <ul>
          <li class="active" v-for="(item, index) in mapList[this.num]" :key="index" @click="one(item)">
            <div class="content">
              <div class="distance"></div>
              <h3>
                <span>{{item.store_name}}</span>
                <img :src="item.mi_icon" />
              </h3>
              <div class="time">{{item.shop_time}}</div>
              <div class="addressDel">{{item.address}}</div>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      markerPoint: { lng: 0, lat: 0 },
      center: { lng: 0, lat: 0 },
      zoom: 3,
      num: 0,
      mapList: []
    }
  },
  created () {
    this.getMapList()
  },
  methods: {
    handler ({ BMap, map }) {
      this.center.lng = 104.123355
      this.center.lat = 30.656013
      this.markerPoint.lng = 104.123355
      this.markerPoint.lat = 30.656013
      this.zoom = 15
    },
    async getMapList () {
      const res = await this.$http.get('map')
      for (let i = 0; i < res.data.data.store_type_list.length; i++) {
        this.mapList.push(res.data.data.store_type_list[i].store_list)
      }
    },
    one (item) {
      this.center.lng = item.position.lng
      this.center.lat = item.position.lat
      this.markerPoint.lat = item.position.lat
      this.markerPoint.lng = item.position.lng
    }
  }
}
</script>
<style lang="less" scoped>
.map {
  width: 100%;
  height: 500px;
}
.btn button {
  margin-top: 5px;
  border: 1px solid #ccc;
  border-radius: 15px;
}
.text {
  margin-top: 5px;
  color: #ccc;
}
.se {
  position: relative;
  right: -20px;
  text-align: center;
  line-height: 20px;
  width: 22px;
  height: 22px;
  border: 1px solid #ccc;
  border-radius: 50%;
}
.header-nav {
  overflow: hidden;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
  position: fixed;
  top: 25px;
  left: 15px;
  right: 15px;
  .go-back {
    width: 28px;
    height: 28px;
    background: #fff;
    border-radius: 0.28rem;
    border: 0.01rem solid #ccc;
    position: relative;
    i {
      position: absolute;
      width: 7px;
      height: 7px;
      top: 50%;
      left: 50%;
      border-left: 1px solid #949494;
      border-bottom: 1px solid #949494;
      -webkit-transform: rotate(45deg);
      transform: rotate(45deg);
      margin-left: -4px;
      margin-top: -4px;
    }
  }
  .local-address {
    height: 28px;
    background: hsla(0, 0%, 100%, 0.9);
    border-radius: 2px;
    border: 1px solid #ccc;
    line-height: 25px;
    z-index: 9;
    position: relative;
    padding: 0 22px 0 15px;
    p {
      font-size: 12px;
      font-family: MI-LANTING_GB-OUTSIDE-YS;
      font-weight: 400;
      color: #000;
      text-align: left;
    }
    i {
    position: absolute;
    width: 0;
    height: 0;
    border-width: 4px 4px 0;
    border-style: solid;
    border-color: gray transparent transparent;
    top: 50%;
    margin-top: -1.5px;
    right: 12px;
}
  }
}
.address-list {
  margin-top: 10px;
  height: 218.75px;
  overflow-y: scroll;
  ul li.active {
    background: #fffcf6;
  }
  ul li {
    width: 100%;
    list-style: none;
    border-bottom: 1px solid hsla(0, 0%, 80%, 0.3);
    .content {
      padding: 11.458px 0;
      text-align: left;
      position: relative;
      overflow: hidden;
      margin: 0 16.667px;
      .distance {
        position: absolute;
        top: 16.667px;
        right: 16.667px;
      }
      h3 {
        height: 21.88px;
        font-size: 16px;
        color: #000;
        line-height: 21.88px;
        font-weight: 400;
        span {
          display: inline-block;
          max-width: 260px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        img {
          width: 16.6px;
          margin-left: 5px;
          vertical-align: 2.5px;
        }
      }
      .time {
        font-size: 12px;
        font-weight: 400;
        color: #000;
        margin: 5px 0;
      }
      .addressDel {
        font-size: 12px;
      }
    }
  }
}
.bg-btn {
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 999;
  background-color: #1989fa;
}
</style>
